<template>
  <div class="home">
    <div class="homeWarp">
      <div class="bannerimgWarp">
        <el-carousel v-if="previewData.bannerImg.length > 0" class="bannerBox">
          <el-carousel-item class="bannerCon" v-for="item in previewData.bannerImg" :key="item.floorInfoImg">
            <el-image :src="item.floorInfoImg" fit="cover"></el-image>
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="recomGoodsWarp">
        <div class="recomTittle">
          <h2>商品推荐</h2>
          <img class="goodsSale" src="@/assets/images/cuxiao.svg" />
          <img src="@/assets/images/more.svg" />
        </div>
        <ul class="goods">
          <li v-for="goods in previewData.goodsList" :key="goods.goodsId">
            <div>
              <img :src="goods.floorInfoImg" class="goodsImg" />
              <div class="goodsinfo">
                <p class="goods-sub">{{ goods.goodsName }}</p>
                <p class="goods-price"><span>￥</span>{{ goods.price }}</p>
              </div>
            </div>
          </li>
        </ul>
      </div>
      <div class="zhongyaoGoodsWarp">
        <div class="zhongyaoTittle">
          <h2>皮肤修复辅料</h2>
          <img src="@/assets/images/more.svg" />
        </div>
        <ul class="goods">
          <li v-for="goods in previewData.insgoods" :key="goods">
            <img :src="goods.floorInfoImg" />
          </li>
        </ul>
      </div>
      <div class="zhongyaoGoodsWarp">
        <div class="zhongyaoTittle">
          <h2>一次性耗材用品</h2>
          <img src="@/assets/images/more.svg" />
        </div>
        <ul class="goods">
          <li v-for="goods in previewData.Hmgoods" :key="goods">
            <img :src="goods.floorInfoImg" />
          </li>
        </ul>
      </div>
      <div class="zhongyaoGoodsWarp">
        <div class="zhongyaoTittle">
          <h2>医用采血管</h2>
          <img src="@/assets/images/more.svg" />
        </div>
        <ul class="goods">
          <li v-for="goods in previewData.Lmgoods" :key="goods">
            <img :src="goods.floorInfoImg" />
          </li>
        </ul>
      </div>
      <!-- <div class="zhongyaoGoodsWarp">
        <div class="zhongyaoTittle">
          <h2>试剂商品</h2>
          <img src="@/assets/images/more.svg" />
        </div>
        <ul class="goods">
          <li v-for="goods in previewData.Reagoods" :key="goods">
            <img :src="goods.floorInfoImg" />
          </li>
        </ul>
      </div>
      <div class="zhongyaoGoodsWarp">
        <div class="zhongyaoTittle">
          <h2>常规商品</h2>
          <img src="@/assets/images/more.svg" />
        </div>
        <ul class="goods">
          <li v-for="goods in previewData.Congoods" :key="goods">
            <img :src="goods.floorInfoImg" />
          </li>
        </ul>
      </div> -->
    </div>
  </div>
</template>

<script setup>
import { reactive, onMounted } from 'vue'
import api from '@/api'
const previewData = reactive({
  bannerImg: [],
  goodsList: [],
  insgoods: [],
  Hmgoods: [],
  Lmgoods: [],
  Reagoods: [],
  Congoods: []
})

const loadData = async () => {
  let { data } = await api.get(`/medinstrument/boss/index/preview`)
  previewData.bannerImg = data.banner

  previewData.goodsList = data.goodsrefer?.map((item) => {
    let { floorInfoVal } = item
    floorInfoVal = JSON.parse(floorInfoVal)
    return {
      ...item,
      ...floorInfoVal[0]
    }
  })
  previewData.insgoods = data.insgoods?.map((item) => {
    return item
  })
  previewData.Hmgoods = data.Hmgoods?.map((item) => {
    return item
  })
  previewData.Lmgoods = data.Lmgoods?.map((item) => {
    return item
  })
  previewData.Reagoods = data.Reagoods?.map((item) => {
    return item
  })
  previewData.Congoods = data.Congoods?.map((item) => {
    return item
  })
}

onMounted(() => {
  loadData()
})
</script>

<style lang="scss" scoped>
.home {
  .homeWarp {
    width: 1080px;
    padding: 0 20px;
    margin: 0 auto;
    position: relative;
    box-sizing: border-box;
    background: #fff;

    .bannerimgWarp {
      height: 329px;
      margin: 0 auto;
      border-radius: 10px;
      overflow: hidden;
      .bannerBox {
        border-radius: 10px;
        .bannerCon {
          border-radius: 10px;
        }
      }
    }

    .recomGoodsWarp,
    .zhongyaoGoodsWarp {
      .recomTittle,
      .zhongyaoTittle {
        margin-top: 20px;
      }
      span {
        font-size: 24px;
        line-height: 32px;
        color: var(--color-text);
        font-weight: 700;
      }

      .more-icon {
        cursor: pointer;
      }
    }

    .recomGoodsWarp {
      .recomTittle {
        display: flex;
        align-items: center;
        height: 32px;
        margin-bottom: 17px;

        .goodsSale {
          margin: 0 10px 0 5px;
        }
      }
      .goods {
        display: flex;
        flex-wrap: wrap;

        li {
          box-sizing: border-box;
          padding: 10px;
          border-radius: 10px;
          overflow: hidden;
          cursor: pointer;
          .goodsImg {
            width: 176px;
            height: 176px;
            border-radius: 10px;
          }

          &:hover {
            box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.15);
            .goodsinfo .goods-sub {
              color: #e86600;
            }
          }
          .goodsinfo {
            margin-top: 10px;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            box-sizing: border-box;
            .goods-sub {
              width: 166px;
              height: 42px;
              line-height: 42px;
              font-size: 16px;
              color: var(--color-text);
              text-align: justify;
              overflow: hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
              margin-bottom: 5px;
            }
            .goods-price {
              width: 47px;
              height: 27px;
              line-height: 27px;
              font-size: 20px;
              color: #e89000;
              font-weight: 600;

              span {
                width: 7px;
                height: 27px;
                line-height: 27px;
                font-size: 12px;
                color: #e89000;
              }
            }
          }
        }

        li:last-child {
          margin-right: 0;
        }
      }
    }
    .zhongyaoGoodsWarp {
      .zhongyaoTittle {
        display: flex;
        align-items: center;
        margin-bottom: 10px;
        span {
          margin-right: 10px;
        }
      }
      .goods {
        display: flex;

        li {
          width: 248px;
          height: 300px;
          border-radius: 10px;
          margin-right: 16px;

          img {
            width: 100%;
            height: 100%;
            border-radius: 10px;
          }
        }
      }
    }

    .zhongyaoGoodsWarp:last-child {
      padding-bottom: 117px;
    }
  }
}
</style>
